package com.dmgo.common;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;

import javax.persistence.*;

/**
 * Created by user on 29.10.2014.
 */


//firstly mapping with our table

@Entity
@Table(name = "way_depo", catalog = "mkyong")
public class Depo {


    private int wayId;
    private Way way;
    private String depoName;
    private String depoDescription;

    //counstructors

    public Depo(Way way, String depoName, String depoDescription) {
        this.way = way;
        this.depoName = depoName;
        this.depoDescription = depoDescription;
    }

    public Depo() {
    }

    public Depo(String depoName, String depoDescription) {
        this.depoName = depoName;
        this.depoDescription = depoDescription;
    }

    public Depo(Way way, String depoName) {
        this.way = way;
        this.depoName = depoName;
    }

    public Depo(int wayId, Way way, String depoName, String depoDescription) {
        this.wayId = wayId;
        this.way = way;
        this.depoName = depoName;
        this.depoDescription = depoDescription;
    }

    public void setWayId(int wayId) {
        this.wayId = wayId;
    }

    public void setWay(Way way) {
        this.way = way;
    }

    public void setDepoName(String depoName) {
        this.depoName = depoName;
    }

    public void setDepoDescription(String depoDescription) {
        this.depoDescription = depoDescription;
    }

//create forength key value

    @GenericGenerator(name = "generator", strategy = "foreign", parameters = @Parameter(name = "property", value = "way"))
    @Id
    @GeneratedValue(generator = "generator")
    @Column(name = "WAY_ID", unique = true, nullable = false)
    public int getWayId() {
        return wayId;
    }

    @OneToOne(fetch = FetchType.LAZY)
    @PrimaryKeyJoinColumn
    public Way getWay() {
        return way;
    }

    @Column(name = "DEPO_NAME", length = 20)
    public String getDepoDescription() {
        return depoDescription;
    }
    @Column(name = "DEPO_DESCRIPTION", length = 200)
    public String getDepoName() {
        return depoName;
    }

    @Override
    public String toString() {
        return "Depo{" +
                "wayId=" + wayId +
                ", way=" + way +
                ", depoName='" + depoName + '\'' +
                ", depoDescription='" + depoDescription + '\'' +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Depo depo = (Depo) o;

        if (wayId != depo.wayId) return false;
        if (depoDescription != null ? !depoDescription.equals(depo.depoDescription) : depo.depoDescription != null)
            return false;
        if (depoName != null ? !depoName.equals(depo.depoName) : depo.depoName != null) return false;
        if (way != null ? !way.equals(depo.way) : depo.way != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = wayId;
        result = 31 * result + (way != null ? way.hashCode() : 0);
        result = 31 * result + (depoName != null ? depoName.hashCode() : 0);
        result = 31 * result + (depoDescription != null ? depoDescription.hashCode() : 0);
        return result;
    }
}
